package com.shilin.watchsystem.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.shilin.watchsystem.entity.Product;
import com.shilin.watchsystem.form.AddProductForm;
import com.shilin.watchsystem.form.EditProductForm;
import com.shilin.watchsystem.mapper.ProductMapper;
import com.shilin.watchsystem.service.IProductService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author jobob
 * @since 2020-08-21
 */
@Service
public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> implements IProductService {

    @Resource
    ProductMapper productMapper;


    @Override
    public void insert(AddProductForm form) {
        Product product = new Product();
        BeanUtils.copyProperties(form,product);
        save(product);
    }

    @Override
    public IPage<Product> page(Page<Product> page) {
        return productMapper.page(page);
    }

    @Override
    public void edit(EditProductForm form) {
        Product product = getById(form.getId());
        BeanUtils.copyProperties(form,product);
        updateById(product);
    }
}
